import {Component, OnInit} from '@angular/core';

import {MENU_ITEMS, USER_MENU_ITEMS} from './pages-menu';
import {AdminService} from "../AdminService";
import {UserService} from "../UserService";
import {Router} from "@angular/router";

@Component({
  selector: 'ngx-pages',
  styleUrls: ['pages.component.scss'],
  template: `
    <ngx-sample-layout>
      <nb-menu [items]="menu"></nb-menu>
      <router-outlet></router-outlet>
    </ngx-sample-layout>
  `,
})
export class PagesComponent implements OnInit{

  menu = MENU_ITEMS;
  constructor(private admin:AdminService,private user:UserService,private router:Router){

  }

  ngOnInit(): void {
    if(this.admin.hasLogin()) {
      if (this.admin.getAdmin().sysId != 1) {
        this.menu.splice(1, 2);
      }
      console.log("Navigate");
      this.router.navigate(['pages/index']);
    }else if(this.user.hasLogin()){
      this.menu = [];
      USER_MENU_ITEMS.forEach(v=>{
        this.menu.push(v);
      });
      this.router.navigate(['pages/usr/profile']);
    }else{
      this.router.navigate(['/auth']);
    }
  }
}
